const cheerio = require('../../node_modules/cheerio');

async function getCollege() {
    var [err, res] = await uni.request({
        url: 'http://211.82.48.36/student/teachingResources/classCurriculum/index'
    });

    if (err) return null

    if (res.data.indexOf("登录") != -1) return null

    console.log(res)

    let $ = cheerio.load(res.data);

    console.log($)

    let resultArr0 = ['未选择'];
    let resultArr1 = [-1];


    $('#departmentNum > option').each((idx, ele) => {
        // console.log(ele)
        let name = $(ele).text() // 获取新闻标题
        let value = $(ele).attr('value') // 获取新闻网页链接
        console.log(name, value)
        resultArr0.push(name);
        resultArr1.push(value);
    });

    // var doc = new dom().parseFromString(res.data, 'text/xml')
    // const doc = htmlparser2.parseDOM(res.data);

    // const node = xpath.fromPageSource(res.data).findElements(
    //     "/html/body/div[4]/div[2]/div[2]/div/div[1]/form[1]/div/div[1]/div[6]/select/option");

    // console.log(node)

    // var result = doc.evaluate(
    //     "/html/body/div[4]/div[2]/div[2]/div/div[1]/form[1]/div/div[1]/div[6]/select/option", doc, null,
    //     XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

    // console.log(result)


    // for (let i = 1; i < result.snapshotLength; i++) {
    //     let nodes = result.snapshotItem(i)
    //     // console.log(nodes, nodes.value, nodes.innerHTML)
    //     let name = nodes.innerHTML
    //     let code = nodes.value
    //     resultArr0.push(name);
    //     resultArr1.push(code);
    // }

    return {
        college: resultArr0,
        collegeIdArr: resultArr1
    }
}

export {
    getCollege
}
